<?php
declare (strict_types = 1);

namespace app\index\controller;


use app\index\BaseController;
use app\index\model\Article;
use app\index\model\Block;
use app\index\model\Topic;
use app\index\model\Category as CategoryModel;

class Category extends BaseController
{


    /**
     * 显示指定的资源
     * @param int $category_id
     * @return \think\response\View
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function read(int $category_id)
    {
        $model = $this->getModel(CategoryModel::class,$category_id);
        return view('read',[
            //分类话题
            'topics' => jsonStr(Topic::getHotTopics(['category_id'=>$category_id])),
            'topicLimit' => Topic::HOT_LIMIT,

            //文章列表
            'count' => Article::getCount(['category_id'=>$category_id]),
            'limit' => Article::LIMIT_NUM,

            //分类模型
            'category' => $model,

            //面包屑
            'crumb' => [
                'home'     => '/',
                $model->name  => request()->url()
            ],

            //*热门文章
            'activeArticles' => Block::getActiveArticles(),
            //热门标签
            'activeTags' => Block::getActiveTags(),
            //*推荐作者
            'activeAuthors' => Block::getActiveAuthors(),
            //*推荐话题
            'activeTopics' => Block::getActiveTopics(),

        ]);
    }

}
